Refactor client side code