Refactored JS code, fixed js linting errors