Fix encode bug (wrong method name used). Add test for decode/encode.