Added debugging code (output to file)