Fixes issue #795.

I’m trying to test it a bit more, but it seems to do the trick.