Ran a static analyzer and fixed some problems