changed output to a variable and added output to file