Code cleanup and reformat