Improved get_state() logic.