Refactored so encoder is more abstracted from CassetteLibrary.
Added docstrings.