minor bugfixes. Closes files after use, and updated to handle utf-8 characters in files.