refactored client side code