First crack at refactoring the codebase. A log of stuff changed there is much that probably doesn’t work.