QD-50 : merged in two patches/pull requests, made more changes, fixed the tests

https://bugs.indeed.com/browse/QD-50

  rebased onto latest from upstream, reapplied same patches, and my same fixes, and fixed the tests.
Might be better to just write "None" to stdout/stderr. Makes it easier to debug.