Added null check for user-agent header