raft: move logic to separate func