Fixes issue #312,#291