Fix build on OSX

Initial patch that builds and runs on OSX. I'm aware that this patch may not follow best practices, please offer any suggestions for improvements if needed. I hope I haven't made many coding standard crimes on this one

Thanks!