Updated search and detect to include better math