added an extended script to fit multiple files