Refactoring and another user agent fix