Recursion logic for finding the changing part