Added enchanced encoding handling