reformatted some logic of search, added in tests to show