add some comments and refactor some code