some bugs fixed thanks to clang static analyzer