Tidy up (pub integration preperation)

This is some tidyup/refactoring I did in the `pub-integration` branch that isn't specifically part of `pub` integration.

Since it might be a while before `pub-integration` gets merged; I think it's worth merging these to avoid having to keep rebasing and fixing conflicts. These changes shouldn't change any functionality, they're just some tidying up.