Simplify waitFor

No need to repeatedly allocate the semaphore
Simplify the switch example