clean up and simplify wallet code