state management improvements and clean-up