Improving code for mod_search