some further refactoring of variable names and code formatting