optimized, using pixels array, eliminating unnecess vars