Fix the tests
improve docs
Use serialization and deserialization to decouple the different states