Nevermind, I think I have the solution (see new diff).