Improve matching of path/hash and last chars

Based on #59, fixes #58