Fix some errors found by coverity

Also fixed some indentation