Refactored based on pull request comments