Fix for #539

With some help from @proteneer, this seems to solve the issue on my mac.