clean up the code and format the result output