Add Union type
Add simple vector support
Refactor common code out of protocol functions