Refactored code due to comments