Removing trailing spaces and adding trailing newlines