Couple more changes: using a param for the number of colors, and removing a
bunch of casts.