Add more checks for ledger parameters, final refactoring.