Add 'state' tracking

Will help us keep track of where in the application we currently are,
which is useful if the script exits unexpectedly (and it's cleaner using
this property than digging through the stacktrace).