Fix semaphore issues