fixes #2539

forward port changes from #2539