Some js refactoring