Modified algorithm for creating the preview