Renaming variables for clarity. Fixed a bug