Refactorred jQuery code