Refactor the client side code