Rewrote the state tramsaction handling.