More refactoring to make it easier to do dependency injection
Merge pull request #3207 from systay/candidate-list

[2.2] More refactoring to make it easier to do dependency injection