incorporate fix from #582