changed the loop indices to int from uint8_t, somehow this prevents the infinite loop