code cleanup and reformat