Updated states function to use all filters in temp table aggrgation.
Last query also changed.