Fix bug in filename replacement