Code refactoring and add comments.
Code refactoring and add comments.