fix for #358 and #351