fix search and add tests