replica manager initial working code