js cleaning and refactoring