Comments added for functional clarity.