Remove filtering products without images
Add setting for default visibility of products
Add missing return statements
Make first images as main, small and thumbnail and not excluded if current main image was removed
Use value for product visibility from website setting
No need to set data for next step where unique images are stores in final product when there's no images in all similar products