Make encoder library stateful

fixes #77