replaced setPixel with setPixels and fixed the race condition