moved some ugly protocol detection to a class
improved protocol detection