Several bug fixes for compiling with Clang