Fix small bugs detected by gcc and clang warnings