Pulled in refactoring done on v1.70 branch