More refactoring, simplifying functions.