More clang fixes.

This fixes more clang issues. Many of them are simple changes, however there is a few that are genuine bugs and that could affect results if the code is actually triggered.