improved serialization, cleanups