js refactored