corrected search_max(), should work much better now