Added gray code stuff