Added support for some basic wait queues and synchronization, lots of bugfixes