Fixed reference errors caused by refactoring.
Renamed variable to prevent shadowing.