A bit of cleanup and refactoring