LPS-35037

Hey László,

This is the final version that I'm going to send to Brian. 
Can you please test it carefully to make sure that we fix the issue and that we don't create any regression?

I have tested it myself and it seems good to me, but I would like somebody else to double check it.

thanks!