remove recursion condition in iterative method