Refactored js