Fix #807 for releases branch

This is a port of #807 to the `releases` branch.

I should probably have based the fix on `releases` from the beginning, and then ported it to master.

Note that with this pull request, merging `releases` back into `master` will produce a conflict. I will submit another pull request that fixes this momentarily.