Refactored to use mocking