Fixed bug in encode
Fixed bugs in encode/decode that caused them to generate backwards results