Refactor all day every day

Hello me,

No change in functionality, just a fair amount of refactoring.