Added semaphores to control concurrency