minor changes
changed sth to work with arbitary indexes