Fixed crashes on OSX