Refactored code into jQuery plugin syntax