Fixed some bugs the static analyzer found.