Add encoding detection

Add encoding detection.