re-factor search operations code