JS refactoring: moved bare code into jQuery plugins