fixes various stuff (tested to work on OSX with clang 3.6)

See #2. Also addresses very similar issues as #1...