Remove extra newlines and duplicate keywords