More refactoring and cleaning up.