Backport PR#180 to fix issue #147