fix buggy code (destroy encoder object)