Js refactor for jQuery plugin