Finish global state machine, improve constants and limits, and other small changes