Fixed semaphore bug