Fixes #2737

If I understand the description right, here is the solution.
Thanks for the fast review! Updated the code (: