Adding replication logic