Code refactoring and comments