Changes to recursive implementation