improved code at main.js