Cherrypicked fix for ticket from e37f