moved semaphore placement for safety