LPS-40898

Hi Tomcsi,

It's the same issue I've already sent to you. I've refactored and hopefully tested all possibilities. I didn't rebase the code as last time I had issues with layout revisions on master without my fixes.

Regards,
Vilmos