port fix from #542