clean the code and add some comments