Fixed outputting to file