Restructured code in main.js