clean up and reformat code