improved logic in search result generation