Working code of global search