Fix for issues #157, #158 and #164

* fix issues #157, #158 and #164
* improved OS X support
* cleanup