Fixing issue #341 and #339.