Some more refactoring and simplifying.