More refactoring to reduce duplicated code.