wait() doc and context switch code improved