Various fixes for Mac and more
Merged code