refactoring for better jquery plugin