Some more refactoring; no API changes