backport D7 changes