Refactored jQuery code