Use a temp file instead of assuming a schema will fit in 9k

This should still almost never actually hit the disk.
Remove some unused code
Wire up the newly-factored-out bits