Changed to extern instead of global for semaphores