Moved setPixel functionality into writePixel