add comments and clean some code