debt: refactor internals