Tail call optimization for search iteration

Fixes #256