Fixed bug and renamed variable for clarity.