Fixing search, adding some tests