Fixing ordering on states query.