Add nil check while finding parents.