Thanks zachborboa for the report and blackguest for the patch. Backport of 7353e26d and 0a2bc6e6 from master