Refactor of main.js to use classes to improve encapsulation.