Fixed issues with serializing illegal classes, see issues #30 and #31.