Encoding fix
Added tests