Improve state tracking and debug information