refactor add switchLeader func