Improved state handling.