I've moved the node creation code into a function I put at the top.