Some more extensions and refactoring.