backported fix from master