fix some errors for compatibility with c++ and mac