Configuration refinements

Improve the code quality of the configuration sub-system: remove some duplications, reduce method complexity, remove some unused code, add some new test cases, improve code coverage, fix some code standard mistakes.
either the `@return` phpdoc is not correct, or this might return `array()` instead?