Some abstraction and refactoring to better handle multiple accounts