refactoring of JS