made most of decode. No idea if anything works because I think something is wrong with encode