Fixed stack usage. Minor changes to OSX build. Fixed some line endings.