minor refactoring, variable renaming for clarity