Refactoring js