refactor search script