Rewrite code with hints from rubocop
Keep current scope when applying search