Some more bug fixes. I think I squashed them all.