clean code and add some comments