Fixed AttributeError in indexing code