integrate fixes from #1988

also, various fixes