A bit of refactoring/cleanup.