changed from sysout to writing to file (2)