Bugfixes

I found some bugs. I fixed them.

(See the commits for the list of the fixed bugs.)