Moving the memcpy out of the mutex lock