Some more refactoring work