add some comments, and format the code