Introduced semaphores to protect reads and writes