r148: fixed a typo (bug)
r149: fixed a segfault
r150: refined the discovery mode