Revert r237539: "Reapply r237520 with another fix for infinite looping"