Improve state management for test