Added comments on algorithm