refactor and some comments