Remove extra characters when joining lines