Cleanup bad code & fixed serialization