major overhaul of discover.cpp