Refactored client side code