Encoding improvements

Most of the reasoning is in the source code. Check out the diff if you're interested in my "research"