Fix swapped reference indices