Fixed a few bugs that were found by Visual Studio's static code analysis.