Replaced mutex with semaphore