Refactoring and adding commments