Refactor 'search 2d matrix' again.