Fix stack overflow on OSX