move encoding detect into initialize