function returnCollateral(uint dealID) public payable {
    REPODeal storage deal = deals[dealID];
    require(deal.state == 2);
    require(block.number < deal.endsAt);
    require(msg.sender == deal.borrower);

    uint payment = deal.collateralAmount + deal.interest;
    if (deal.collateral == 0) {
      require(msg.value == payment);
      require(deal.lender.send(msg.value));
    } else {
      require(ERC20(deal.collateral).transferFrom(msg.sender, deal.lender, payment));
    }

    sendGoods(deal.pledge, deal.borrower, deal.pledgeAmount);

    deal.state = 3;
    CollateralReturned(dealID);
  }