updated index, added logic