fix matchprefix bug and add test case; still doing lazy thing I guess