add more comment on algorithm