Major refactor into separate, more testable classes

Still testing manually since I don't have good overall coverage. That's coming soon...