add better solution for search matrix