Add wait function to handle Ajax calling