Renamed some variables to be less confusing.

At least I hope so.