Added comments which explain the algorithm