contract MyRefundableCrowdsale is FinalizableCrowdsale {
  using SafeMath for uint256;

  // minimum amount of funds to be raised in weis
  uint256 public goal;

  // refund vault used to hold funds while crowdsale is running
  MyRefundVault public vault;

  function MyRefundableCrowdsale(uint256 _goal) public {
    require(_goal > 0);
    vault = new MyRefundVault(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 claimRefundOnUnsuccessfulEvent() public {
    require(isFinalized);
    require(!goalReached());
    uint256 refundedValue = vault.myRefund(msg.sender);
    weiRaised = weiRaised.sub(refundedValue);
  }

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

    super.finalization();
  }

  function goalReached() public view returns (bool) {
    return weiRaised >= goal;
  }

  function getDeposit(address contributor) public view returns(uint256 depositedValue) {
    return vault.getDeposit(contributor);
  }

  function pauseRefund() public onlyOwner {
  	vault.pause();
  }

  function unpauseRefund() public onlyOwner {
    vault.unpause();
  }

  function isRefundPaused() public view returns(bool) {
    return vault.isRefundPaused();
  }
}
function forwardFunds() internal {
  vault.deposit.value(msg.value)(msg.sender);
}

// We're overriding the fund forwarding from Crowdsale.
// In addition to sending the funds, we want to call
// the RefundVault deposit function