fixing async issue with jquery