removing the recursion for the search
replacing dirty print by real logs