Manual cherry pick of PR #3135

Credit goes to @mhvk