refactor replication functions