Refactor to ease testing