serialization stackoverflow fix

This should have generic typing, but we can do that later.