contract RefundableCrowdsale is FinalizableCrowdsale {
    using SafeMath for uint256;

    // minimum amount of funds to be raised in weis
    uint256 internal goal;
    bool internal _goalReached = false;
    // refund vault used to hold funds while crowdsale is running
    RefundVault private vault;

    constructor(uint256 _goal) public {
        require(_goal > 0);
        vault = new RefundVault(wallet);
        goal = _goal;
    }

    // We're overriding the fund forwarding from Crowdsale.
    // In addition to sending the funds, we want to call
    // the RefundVault deposit function
    function forwardFunds() internal {
        vault.deposit.value(msg.value)(msg.sender);
    }

    // if crowdsale is unsuccessful, investors can claim refunds here
    function claimRefund() public {
        require(isFinalized);
        require(!goalReached());

        vault.refund(msg.sender);
    }

    // vault finalization task, called when owner calls finalize()
    function finalization() internal {
        if (goalReached()) {
            vault.close();
        } else {
            vault.enableRefunds();
        }
        super.finalization();
    }

    function goalReached() public returns (bool) {
        if (weiRaised >= goal) {
            _goalReached = true;
        }

        return _goalReached;
    }

    //  function updateGoalCheck() onlyOwner public {
    //    _goalReached = true;
    //  }

    function getVaultAddress() onlyOwner public view returns (address) {
        return vault;
    }
}
function claimRefund() public {
    require(isFinalized);
    require(!goalReached());

    vault.refund(msg.sender);
}

// if crowdsale is unsuccessful, investors can claim refunds here