porting changes from OSX branch