better newline removal and semicolon addition