Make legacy file matching a bit more robust