Refactor things a bit

Move the generic incremental loading into its own function
so we don't end up taking two 64k buffers on the stack when
one is enough.