Code refactoring for tests