foldLeft instead of foldRight, filter by seen nodes