correct semaphore usage
Fixed problems