Remove trailing whitespace and adjust newlines