Updated bruteforce search algorithm