Refactoring for new replication function