Issue #18833: Refactored code to eliminate some redundancy and fix id issue