Improve matching

* Handle filename matching
* Prefer matching touching letters, ab_b_c will match the first ab
* Clean up code