Fix a number of small mistakes

Running a static analyzer on random github repos. Here are a few fixes. I'll open a bug for the rest.