add some comments and refacto