Shuffled around some code to make adding an API blueprint easier + misc cleanups.