fix for #1345 and partial fix for #1310