Various fixes from @cadr-sa. Issue #84