Ugly backward loop with index