Move work into it's own func

Thinking about making the loop concurrent.
First step, move it into a function.