Fix indexing

Several off-by-one errors and row/column errors