Changed loop variables to uint8_t for lower memory usage.