added semaphore protection