Minor refactoring and cleaning up some messy tests