Rewrite of the foldLine function in order to fold correctly in case of