Imported changes from D6.