Refactoring of JS