fix recursion; add comments