LPS-44724 fix incorrect logic and performance regression