fixed indexing bugs, other clean up