make recursion work properly