Added checks for recursion.