Began refactor of main.js