refactor replication prevention logic