contract AbstractToken is Token, SafeMath {
  /**
   * Get total number of tokens in circulation.
   *
   * @return total number of tokens in circulation
   */
  function totalSupply () constant returns (uint256 supply) {
    return tokensCount;
  }

  /**
   * Get number of tokens currently belonging to given owner.
   *
   * @param _owner address to get number of tokens currently belonging to the
            owner of
   * @return number of tokens currently belonging to the owner of given address
   */
  function balanceOf (address _owner) constant returns (uint256 balance) {
    return accounts [_owner];
  }

  /**
   * Transfer given number of tokens from message sender to given recipient.
   *
   * @param _to address to transfer tokens from the owner of
   * @param _value number of tokens to transfer to the owner of given address
   * @return true if tokens were transferred successfully, false otherwise
   */
  function transfer (address _to, uint256 _value) returns (bool success) {
    return doTransfer (msg.sender, _to, _value);
  }

  /**
   * Transfer given number of tokens from given owner to given recipient.
   *
   * @param _from address to transfer tokens from the owner of
   * @param _to address to transfer tokens to the owner of
   * @param _value number of tokens to transfer from given owner to given
            recipient
   * @return true if tokens were transferred successfully, false otherwise
   */
  function transferFrom (address _from, address _to, uint256 _value)
  returns (bool success)
  {
    if (_value > approved [_from][msg.sender]) return false;
    if (doTransfer (_from, _to, _value)) {
      approved [_from][msg.sender] =
        safeSub (approved[_from][msg.sender], _value);
      return true;
    } else return false;
  }

  /**
   * Allow given spender to transfer given number of tokens from message sender.
   *
   * @param _spender address to allow the owner of to transfer tokens from
            message sender
   * @param _value number of tokens to allow to transfer
   * @return true if token transfer was successfully approved, false otherwise
   */
  function approve (address _spender, uint256 _value) returns (bool success) {
    approved [msg.sender][_spender] = _value;
    Approval (msg.sender, _spender, _value);
    return true;
  }

  /**
   * Tell how many tokens given spender is currently allowed to transfer from
   * given owner.
   *
   * @param _owner address to get number of tokens allowed to be transferred
   *        from the owner of
   * @param _spender address to get number of tokens allowed to be transferred
   *        by the owner of
   * @return number of tokens given spender is currently allowed to transfer
   *         from given owner
   */
  function allowance (address _owner, address _spender)
  constant returns (uint256 remaining) {
    return approved [_owner][_spender];
  }

  /**
   * Create given number of new tokens and give them to given owner.
   *
   * @param _owner address to given new created tokens to the owner of
   * @param _value number of new tokens to create
   */
  function createTokens (address _owner, uint256 _value) internal {
    if (_value > 0) {
      accounts [_owner] = safeAdd (accounts [_owner], _value);
      tokensCount = safeAdd (tokensCount, _value);
    }
  }

  /**
   * Perform token transfer.
   *
   * @param _from address to transfer tokens from the owner of
   * @param _to address to transfer tokens to to the owner of
   * @param _value number of tokens to transfer
   * @return true if tokens were transferred successfully, false otherwise
   */
  function doTransfer (address _from, address _to, uint256 _value)
  private returns (bool success) {
    if (_value > accounts [_from]) return false;
    if (_value > 0 && _from != _to) {
      accounts [_from] = safeSub (accounts [_from], _value);
      accounts [_to] = safeAdd (accounts [_to], _value);
      Transfer (_from, _to, _value);
    }
    return true;
  }

  /**
   * Total number of tokens in circulation.
   */
  uint256 tokensCount;

  /**
   * Maps addresses of token owners to states of their accounts.
   */
  mapping (address => uint256) accounts;

  /**
   * Maps addresses of token owners to mappings from addresses of spenders to
   * how many tokens belonging to the owner, the spender is currently allowed to
   * transfer.
   */
  mapping (address => mapping (address => uint256)) approved;
}
/**
 * Abstract base contract for contracts implementing Token interface.
 */
function approve (address _spender, uint256 _value) returns (bool success) {
  approved [msg.sender][_spender] = _value;
  Approval (msg.sender, _spender, _value);
  return true;
}

/**
 * Allow given spender to transfer given number of tokens from message sender.
 *
 * @param _spender address to allow the owner of to transfer tokens from
 message sender
 * @param _value number of tokens to allow to transfer
 * @return true if token transfer was successfully approved, false otherwise
 */