fix crash by checking len(v) before accessing v[0]