clean up state a bit, add comments