Change vid encoding so that we only encode to base 64 on serialization

Also change a couple of asserts to runtime checks
where appropriate.