Optimized the thumbnail handling