More refactoring, cleaning up code.