refactoring main.js into separate parts