Refactoring and putting in comments