Reformat and clean-up code