updated pairwise with writing correct filenames