Fix errors and warnings detected by clang