move out some detection code into test program.