Refactoring and adding comments.