fixed indexing bugs.