Refactoring but encoding detection not working anymore!