Restructure referenced files to remove duplicates