backported a bugfix from master