Fixed an issue with the waiting logic