make replication threading-safe