Fix indexing problems