Remove trailing spaces and consecutive newlines