WIP: Fixed #2079

This PR fixes issue #2079, but at the moment it is still work in progress.
I got an error at some point because r was not a Variable apperantly. That is why changed but it is easy to revert it back, if you say so!