refactored js