Factor out encode lib

How does this look for the encode lib?  The basic module is working for me, but it's not clear to me how to incorporate it into your current framework.