Fixes issue #341 and #340