changed from sysout to writing to file