remove an unused function and add comments
Some code refactoring and some comments