refactor and added comment