Improved the performance by avoid a O(n) lookup in states