```\ndebt_amount: uint256 = self._debt(_position_uid)\n    margin_debt_ratio: uint256 = position.margin_amount * PRECISION / debt_amount\n\n\n    amount_out_received: uint256 = self._swap(\n        position.position_token, position.debt_token, _reduce_by_amount, min_amount_out\n    )\n\n\n    # reduce margin and debt, keep leverage as before\n    reduce_margin_by_amount: uint256 = (\n        amount_out_received * margin_debt_ratio / PRECISION\n    )\n    reduce_debt_by_amount: uint256 = amount_out_received - reduce_margin_by_amount\n\n\n    position.margin_amount -= reduce_margin_by_amount\n\n\n    burnt_debt_shares: uint256 = self._repay(position.debt_token, reduce_debt_by_amount)\n    position.debt_shares -= burnt_debt_shares\n    position.position_amount -= _reduce_by_amount\n```\n