main.js added and separation of logic