contract CredoIco is StandardToken, SafeMath {
    // Descriptive properties
    string public constant name = "Credo ICO Token";
    string public constant symbol = "CREDOICO";
    uint256 public constant decimals = 18;
    string public version = "1.0";

    // Account for ether proceed.
    address public etherProceedsAccount;

    // These params specify the start, end, min, and max of the sale.
    bool public isFinalized;
    uint256 public fundingStartBlock;
    uint256 public fundingEndBlock;

    uint256 public constant tokenCreationCap =  375200000 * 10**decimals;
    uint256 public constant tokenCreationMin =  938000 * 10**decimals;

    // Setting the exchange rate for the first part of the ICO.
    uint256 public constant credoEthExchangeRate = 3752;

    // Events for logging refunds and token creation.
    event LogRefund(address indexed _to, uint256 _value);
    event CreateCredoIco(address indexed _to, uint256 _value);

    // constructor
    function CredoIco(address _etherProceedsAccount, uint256 _fundingStartBlock, uint256 _fundingEndBlock)
    {
      isFinalized                    = false;
      etherProceedsAccount           = _etherProceedsAccount;
      fundingStartBlock              = _fundingStartBlock;
      fundingEndBlock                = _fundingEndBlock;
      totalSupply                    = 0;
    }

    function createTokens() payable external {
      if (isFinalized) throw;
      if (block.number < fundingStartBlock) throw;
      if (block.number > fundingEndBlock) throw;
      if (msg.value == 0) throw;

      uint256 tokens = safeMult(msg.value, credoEthExchangeRate);
      uint256 checkedSupply = safeAdd(totalSupply, tokens);

      if (tokenCreationCap < checkedSupply) throw;

      totalSupply = checkedSupply;
      balances[msg.sender] += tokens;
      CreateCredoIco(msg.sender, tokens);
    }

    function finalize() external {
      if (isFinalized) throw;
      if (msg.sender != etherProceedsAccount) throw;
      if (totalSupply < tokenCreationMin) throw;
      if (block.number <= fundingEndBlock && totalSupply != tokenCreationCap) throw;

      isFinalized = true;

      if (!etherProceedsAccount.send(this.balance)) throw;
    }

    function refund() external {
      if (isFinalized) throw;
      if (block.number <= fundingEndBlock) throw;
      if (totalSupply >= tokenCreationMin) throw;
      uint256 credoVal = balances[msg.sender];
      if (credoVal == 0) throw;
      balances[msg.sender] = 0;
      totalSupply = safeSubtract(totalSupply, credoVal);
      uint256 ethVal = credoVal / credoEthExchangeRate;
      LogRefund(msg.sender, ethVal);
      if (!msg.sender.send(ethVal)) throw;
    }

}
/////////////////////
function CredoIco(address _etherProceedsAccount, uint256 _fundingStartBlock, uint256 _fundingEndBlock)
{
  isFinalized                    = false;
  etherProceedsAccount           = _etherProceedsAccount;
  fundingStartBlock              = _fundingStartBlock;
  fundingEndBlock                = _fundingEndBlock;
  totalSupply                    = 0;
}

// constructor