More refactoring to reduce duplication