Rewrote file writing and printing.

I still want to combine the two.