Improve contacts search and add tests