fix for issues #321 and 258