Moving code to useful places.

# Do not merge.

---

I'm working on moving the code out into testable units.