Code refactoring to improve test coverage (I)