some code improvements for search