Not a solution
Turns out I misunderstood the problem. Now this code has to be adjusted.