Refactoring and additional commentaries.