Some comments added to help understanding the flow.