Updated regenerate function to wrap entire function in copyMutex lock.