failover mechanism code refactor