Refactoring in response to feedback on #5754.