full refactor and ability to setdefault encoding