Semaphore bug fixes