working version of search in hierarchy