use with statement for file operations (some files were not closed even)