Robustly validate input to the 'ledger' RPC command
Fix Application singleton pointer lifetime