Unrolling some loops to try and gain speed.

untested! use at your own risk

(sorry about the last two commits, a terrible side effect of editing in-browser).