Finished refactoring.

Urgh.