Fix various warnings and C++ errors.