More refactoring to make code clearer.