Small refactoring (tests still need more refactoring)