handle trailing newlines