Changed from semaphore to locking mechanism