Reformat and rearrange code according to template.