Splitting tasks out into functions, adding further comments, restructuring the creation of the magic packet.