Minor reorganization and variable name change for clarity