Made some fixes to search function.