LPS-43974 and LPS-42531

I have tested the solution and it fixes the problem, but please do some further testing of possible regressions