contract ERC20Token is ERC20Interface, Owned, SafeMath {

    // Account balances
    //
    mapping(address => uint256) balances;

    // Account holder approves the transfer of an amount to another account
    //
    mapping(address => mapping (address => uint256)) allowed;

    // Get the account balance for an address
    function balanceOf(address _owner) constant 
      returns (uint256 balance)
    {
      return balances[_owner];
    }

    // ------------------------------------------------------------------------
    // Transfer the balance from owner's account to another account
    // ------------------------------------------------------------------------
    function transfer(address _to, uint256 _amount) 
      returns (bool success)
    {
      require( _amount > 0 );                              // Non-zero transfer
      require( balances[msg.sender] >= _amount );          // User has balance
      require( balances[_to] + _amount > balances[_to] );  // Overflow check

      balances[msg.sender] -= _amount;
      balances[_to] += _amount;
      Transfer(msg.sender, _to, _amount);
      return true;
    }

    // ------------------------------------------------------------------------
    // Allow _spender to withdraw from your account, multiple times, up to
    // _amount. If this function is called again it overwrites the
    // current allowance with _amount.
    // ------------------------------------------------------------------------
    function approve(address _spender, uint256 _amount) 
      returns (bool success)
    {
      // before changing the approve amount for an address, its allowance
      // must be reset to 0 to mitigate the race condition described here:
      // cf https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
      require( _amount == 0 || allowed[msg.sender][_spender] == 0 );
        
      // the approval amount cannot exceed the balance
      require (balances[msg.sender] >= _amount);
        
      allowed[msg.sender][_spender] = _amount;
      Approval(msg.sender, _spender, _amount);
      return true;
    }

    // ------------------------------------------------------------------------
    // Spender of tokens transfer an amount of tokens from the token owner's
    // balance to another account. The owner of the tokens must already
    // have approve(...)-d this transfer
    // ------------------------------------------------------------------------
    function transferFrom(address _from, address _to, uint256 _amount) 
    returns (bool success) 
    {
      require( _amount > 0 );                              // Non-zero transfer
      require( balances[_from] >= _amount );               // Sufficient balance
      require( allowed[_from][msg.sender] >= _amount );    // Transfer approved
      require( balances[_to] + _amount > balances[_to] );  // Overflow check

      balances[_from] -= _amount;
      allowed[_from][msg.sender] -= _amount;
      balances[_to] += _amount;
      Transfer(_from, _to, _amount);
      return true;
    }

    // ------------------------------------------------------------------------
    // Returns the amount of tokens approved by the owner that can be
    // transferred by _spender
    // ------------------------------------------------------------------------

    function allowance(address _owner, address _spender) constant 
    returns (uint256 remaining)
    {
      return allowed[_owner][_spender];
    }

}
// ----------------------------------------------------------------------------
//
// ERC Token Standard #20
//
// note that totalSupply() is not defined here
//
// ----------------------------------------------------------------------------
function balanceOf(address _owner) constant 
  returns (uint256 balance)
{
  return balances[_owner];
}

// Get the account balance for an address