Refactoring for easier testing of some methods