manual merge & new PR from #531

#531 can be closed and we can merge this one instead. It straddled the repo refactor and had to be manually merged here.