Added support for Mac OSX

Changes merged from AMXX.