Improved search logic.