Made a few changes on semaphores