Applied and tweaked smart-import patch from Mij, merging with 1.16.