removed accumul based recursion with simpler filter