Refactor jquery plugin