contract WhitelistedCrowdsale is Crowdsale, Ownable {

  mapping(address => bool) public whitelist;
  //@dev this addres that allow add or remove adresses to whiteList.
  address whiteListAgent;
  
  //@dev set to whiteListAgent address
  function setWhiteListAgent(address _agent) public onlyOwner{
      require(_agent != address(0));
      whiteListAgent = _agent;
  }
  //@dev revert if sender is whiteListAgent
    modifier OnlyWhiteListAgent() {
        require(msg.sender == whiteListAgent);
        _;
    }
  /**
   * @dev Reverts if beneficiary is not whitelisted. Can be used when extending this contract.
   */
  modifier isWhitelisted(address _beneficiary) {
    require(whitelist[_beneficiary]);
    _;
  }
  
  function inWhiteList(address _beneficiary) public view returns(bool){
      return whitelist[_beneficiary];
  }

  /**
   * @dev Adds single address to whitelist.
   * @param _beneficiary Address to be added to the whitelist
   */
  function addToWhitelist(address _beneficiary) external OnlyWhiteListAgent {
    whitelist[_beneficiary] = true;
  }
  
  /**
   * @dev Adds list of addresses to whitelist. Not overloaded due to limitations with truffle testing. 
   * @param _beneficiaries Addresses to be added to the whitelist
   */
  function addManyToWhitelist(address[] _beneficiaries) external OnlyWhiteListAgent {
    for (uint256 i = 0; i < _beneficiaries.length; i++) {
      whitelist[_beneficiaries[i]] = true;
    }
  }

  /**
   * @dev Removes single address from whitelist. 
   * @param _beneficiary Address to be removed to the whitelist
   */
  function removeFromWhitelist(address _beneficiary) external OnlyWhiteListAgent {
    whitelist[_beneficiary] = false;
  }

  /**
   * @dev Extend parent behavior requiring beneficiary to be in whitelist.
   * @param _beneficiary Token beneficiary
   * @param _weiAmount Amount of wei contributed
   */
  function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal isWhitelisted(_beneficiary) {
        super._preValidatePurchase(_beneficiary, _weiAmount);
  }

}
function addManyToWhitelist(address[] _beneficiaries) external OnlyWhiteListAgent {
  for (uint256 i = 0; i < _beneficiaries.length; i++) {
    whitelist[_beneficiaries[i]] = true;
  }
}

/**
 * @dev Adds list of addresses to whitelist. Not overloaded due to limitations with truffle testing. 
 * @param _beneficiaries Addresses to be added to the whitelist
 */