Refactored and added comment