Fix find target implementation.

Note: for long files, the function will take quite some time
and apparently the framework runs the search in UI thread(!), so
it may block the program for a long time.