TRQ-1426 Cleaned up and more thoroughly checked the routine against QA's improved test.