[TASK] Clean up main JavaScript

The main JS code would be much better structured if it used a class
for wrapping all the application-related code.