refactoring client side code