Fixed indexing bugs