Fixes #988. Fixes #804. Again, but simpler and doesn't break other stuff.