LPS-38405 fix bug in preview (we have formatted the code to make it easier to understand)