refactor of Search Images function