Added code to properly wait