```\nfunction repay (uint256 loanID, uint256 repaid) external {\n    Loan storage loan = loans[loanID];\n\n    if (block.timestamp > loan.expiry) \n        revert Default();\n    \n    uint256 decollateralized = loan.collateral * repaid / loan.amount;\n\n    if (repaid == loan.amount) delete loans[loanID];\n    else {\n        loan.amount -= repaid;\n        loan.collateral -= decollateralized;\n    }\n\n    debt.transferFrom(msg.sender, loan.lender, repaid);\n    collateral.transfer(owner, decollateralized);\n}\n```\n