Fix some mistakes

Did a static analysis run and fixed a few of the issues it found. I will file bugs for the remainder.