changes for #5219 accidentally reverted unrelated changes made by other commits. Restore those & remove some dead code that was commented out.
changes for #5219 accidentally reverted unrelated changes made by other commits. Restore those & remove some dead code that was commented out.