A bunch of refactoring and repurposing