Refactored a lot of jQuery code