cleaned code, select for search type