Pausing and resuming implemented, and some other improvements of the state handling.