overhaul of accounts code and some better error messages