fixing semaphore problems