various patches to make encoding of screen data more efficient and predictable