refactoring + sketch of replication routing logic