WIP: Fixed #2079

This PR fixes issue #2079, but at the moment it is still work in progress.