Expand the use of the mutex to prevent race conditions