Wait queues

Merged in the wait_queue functionality to Master