Code cleanup + gray codes (no cache). Improve test cases.