Iterative main and search