refactoring and update code comments