Added more fuzzy logic for state changes.