Split up work into functions in case we want to parallelize things