Hmm, maybe using macros to make the scanning variable j implicit? I'll try that when I have some more time...