Added semaphore code