Refactored the code using JS Beautify