Reworked encode_line