Further refactoring to ease testing