fixing indexing bug