Refactored client side code for modularity and maintainability.