refactored some code for accounts management