refactored JS