Added recursive function to find the top parent