Basic save state functionality, no loading.

What is this function actually trying to do? Could use a brief documentation comment, since the code is a little cryptic.