refactoring and added comment