Slightly different fix to #580. Closes #580