Cleaned up code, removed extra semaphores