Create jquery plugin and refactor some methods.