functional recursion counter