Pull out actual code writing into it's own file.