refactor. add some comments