Added semaphores which allow interaction between various threads.