Bug fixes for encoding with the runlength included and inversion for merge optimization for later