Backporting fixes from 6.0 trunk to 5.1