Fix for #2024

This PR should fix #2024.

Replaces #2171.