Serious redundancy reduction in main.js