Refactor functions

Refactored `add_states`, `_update_node_observed_status`, `_no_missing_states_function` and `_no_extra_states`. And add `_update_rule_for_states`