Fixing indexing bug