Added comments, renamed variables for clarity