fixed unclosed file buffers
replaced sysout with outln