Search function and tests