Started refactoring the JavaScript to ensure scalability and readability.