Fix for bug 780

And bug 875, which is pretty much the same it looks like.