Fix OSX compilation and behavior