Remove tail calls in search implementation.