Lots of tiny refactorings

Thanks @dkubb