added better algorithm explanation, fixed some PR comments