fixing serialization

fixed a bunch of issues with encoding and code generation