```\n    function handleBadDebt(Types.State storage state, address liquidatedTrader)\n        external\n    {\n        if (\n            state.openPositions[liquidatedTrader].length == 0 &&\n            !Liquidation._isSafe(state, liquidatedTrader)\n        ) {\n            int256 primaryCredit = state.primaryCredit[liquidatedTrader];\n            uint256 secondaryCredit = state.secondaryCredit[liquidatedTrader];\n            state.primaryCredit[state.insurance] += primaryCredit;\n            state.secondaryCredit[state.insurance] += secondaryCredit;\n            state.primaryCredit[liquidatedTrader] = 0;\n            state.secondaryCredit[liquidatedTrader] = 0;\n            emit HandleBadDebt(\n                liquidatedTrader,\n                primaryCredit,\n                secondaryCredit\n            );\n        }\n    }\n```\n