The rest of this PR is just code cleanup. Note that since we use `File::baseName()`, it doesn't matter if all the detections are in a single template, or one detection per template and multiple templates with the same file name.