refactoring client side code for better structure