Refactoring.
Mostly works.