wrote getNexthop function