Fix indexing bug