Fixed getIndex calculation