add newlines in appropriate places