cleaned up serialization code and added testing