Refactoring and comments addition