fixed code for serializing all objects and classes