Enh: refactored ledger code