added gray code ordering