refactoring of main.js