clean up the code and reformat