Fix semaphore bug