fix #48 and more...

all tests are passing.
tested command line build + run on osx
tested programmatic build + run on osx