fix matching logic