Additional comments added and variable identifiers revised for clarity.