refactor code, remove global State object, replace with QueryIndexList