contract TokenCappedCrowdsale is Crowdsale {
    using SafeMath for uint256;

    uint256 public tokenCap = 0;

    // Amount of LPC raised
    uint256 public tokensRaised = 0;

    // Event for manual refund of cap overflow
    event CapOverflow(address sender, uint256 weiAmount, uint256 receivedTokens);

    /**
     * @notice Checks whether the tokenCap has been reached.
     * @return Whether the tokenCap was reached
     */
    function capReached() public view returns (bool) {
        return tokensRaised >= tokenCap;
    }

    /**
     * @notice Update the amount of tokens raised & emit cap overflow events.
     */
    function _updatePurchasingState(address _beneficiary, uint256 _weiAmount) internal {
        super._updatePurchasingState(_beneficiary, _weiAmount);
        uint256 purchasedTokens = _getTokenAmount(_weiAmount);
        tokensRaised = tokensRaised.add(purchasedTokens);

        if (capReached()) {
            // manual process unused eth amount to sender
            emit CapOverflow(_beneficiary, _weiAmount, purchasedTokens);
        }
    }

}
/**
 * @title TokenCappedCrowdsale
 * @dev Crowdsale with a limit for total minted tokens.
 */
function capReached() public view returns (bool) {
    return tokensRaised >= tokenCap;
}

/**
 * @notice Checks whether the tokenCap has been reached.
 * @return Whether the tokenCap was reached
 */