refactoring the main.js code to combine the if calls