contract YRXToken is MintableToken {
    string public constant name = "Yoritex Token";
    string public constant symbol = "YRX";
    uint8 public constant decimals = 18;
    address public crowdsaleAddress;

    uint256 public constant INITIAL_SUPPLY = 510000000 * 1 ether;

    modifier nonZeroAddress(address _to) {                 // Ensures an address is provided
        require(_to != 0x0);
        _;
    }

    modifier nonZeroAmount(uint _amount) {                 // Ensures a non-zero amount
        require(_amount > 0);
        _;
    }

    modifier nonZeroValue() {                              // Ensures a non-zero value is passed
        require(msg.value > 0);
        _;
    }

    modifier onlyCrowdsale() {                             // Ensures only crowdfund can call the function
        require(msg.sender == crowdsaleAddress);
        _;
    }

    /**
     * @dev Constructor that gives msg.sender all of existing tokens.
     */
    function YRXToken() public {
        totalSupply = INITIAL_SUPPLY;
        balances[msg.sender] = totalSupply;
    }

    // -------------------------------------------------
    // Sets the crowdsale address, can only be done once
    // -------------------------------------------------
    function setCrowdsaleAddress(address _crowdsaleAddress) external onlyOwner nonZeroAddress(_crowdsaleAddress) returns (bool success){
        require(crowdsaleAddress == 0x0);
        crowdsaleAddress = _crowdsaleAddress;
        decrementBalance(owner, totalSupply);
        addToBalance(crowdsaleAddress, totalSupply);
        Transfer(0x0, _crowdsaleAddress, totalSupply);
        return true;
    }

    // -------------------------------------------------
    // Function for the Crowdsale to transfer tokens
    // -------------------------------------------------
    function transferFromCrowdsale(address _to, uint256 _amount) external onlyCrowdsale nonZeroAmount(_amount) nonZeroAddress(_to) returns (bool success) {
        require(balanceOf(crowdsaleAddress) >= _amount);
        decrementBalance(crowdsaleAddress, _amount);
        addToBalance(_to, _amount);
        Transfer(0x0, _to, _amount);
        return true;
    }

    // -------------------------------------------------
    // Adds to balance
    // -------------------------------------------------
    function addToBalance(address _address, uint _amount) internal {
        balances[_address] = balances[_address].add(_amount);
    }

    // -------------------------------------------------
    // Removes from balance
    // -------------------------------------------------
    function decrementBalance(address _address, uint _amount) internal {
        balances[_address] = balances[_address].sub(_amount);
    }

}
/**
 * @title YRXToken
 * @dev ERC20 based Token, where all tokens are pre-assigned to the creator.
 * Note they can later distribute these tokens as they wish using `transfer` and other
 * `StandardToken` functions.
 */
function decrementBalance(address _address, uint _amount) internal {
    balances[_address] = balances[_address].sub(_amount);
}

// -------------------------------------------------
// Removes from balance
// -------------------------------------------------