Fix loop indices and make size flexible.
Pulling out struct methods to global

Ensuring all variables are passed as args. Starting the process of
removing global mutable state.
Performance cost from globalising swap but...

I intend to eliminate all need for swap at a later stage.
curlf move sped things up substantially I think.