A bit of refactoring and clean up.