Fix issue #160 and #182