Implemented a fancier version of the wait function.
Merge pull request #2 from Wieke/FancyWaitFIx

Implemented a fancier version of the wait function.