refactored protocol matching