Fixed indexing bugs.