Fixes issue #345 and issue #348

#345 and #348