Fix serialization bug, improve garbage collection