Simplify pixel manipulation code