Ben's changes to encoder library.

This commit is the changes made by Ben on top of your branch. This does not however include his encoder tests.