refactored JS file