Added semaphore guards to prevent