Fixed some weak parts.

Fixed some issues from Clang static analyzer