Refactor wallet code.