First major refactoring to match MRI transcoding algorithm.