Refactoring enc stuff. Could be buggy.