Backported fixes from master1.4