added comment and minor refactoring