minor refactoring and variable name change for readability