clean the code, add some comments, and delete unused variables