finished _encode method, have to test