Optimized generation of the image
Added threading support