Added encoding/decoding, speeds up things a lot