incorporate fix from #830