Much better implementation, and only showing diffs in state changes to make it easier to read