Fix some crashes on macosx