Refactoring and comments added