Refactoring of JS code.