rewrite ugly user agent function