More refactoring of duplicate code