renamed v.id to v.index; changed function order