replaced reduce with getIndex to simplify things