Fix some pre, post conditions in search function