Rewrote state diagram