Better fix for #3065, also fixes #3072.