Begun refactor of main.js