Refactored search to avoid trailing '\0' in the key.