add tests, fix serialization