Remove trailing whitespace and superfluous newlines