Fixes #843 did a quick test, will test again before merge.