Fixes #1272 and hopefully #770