Some more refactoring and housekeeping.