Implemented semaphore. Fixed bug with premature waitabort.