applying changes from #1521