OS X compilation fixes and bug fixes
final bug fixes
Mem leaks still remain though