Refactoring js plugin