e.c algorithm heavily annotated