add unit test and change the detect order