debugged search for some edge cases