Kill the global variable and refactor searching