Backport #1872

Backport #1872, also fixes #3048