rewrite ugly user agent function

:smile: