Further refactoring to hopefully improve design