More refactoring. I believe everything works.