Improved state detection.