Refactored for tests