backported fixes from main tree