Fixed more bugs caught by coverity scan