Hindsight is always 20/20. You can't write out an impromptu before it's played.
I still disagree with the arrays though. Everything else besides that one chunk of code is in it's own little tidy loop.
...And fine, I'll edit in your 'condensed' modulous version. ...Actually, nope. You forgot the modulous maths for the csets.