encode and decode arbitrary erlang terms
bugfix found by testing
added tests