Bug fixes to search function.