a fix for the $index is off by one