Bug fix: bad index bounds caused segfaults