fixed encoding bugs