made some progress refactoring main.js