Implement fuzzy matching

Fix #315.
New commit should fix #373.