fixed some indexing bugs