Thanks Carl Meyer and Tim Graham for the reviews and to all involved in the discussion. Backport of 18c0aaa9 from master