refining matching logic