Fix for issue #169 and #181