Backport parts of 766c8b190bb
Remove legacy code