Refactorings of encoder infrastructure and encoder tool. Still some ugly
patches had to be included, but they can be weeded out later.
Added TODOs and changes.