Fix compile warnings and errors found by clang