added comments and changed variable names for clarity.