Reduced the complexity of discover function.