Fixed fd leak where files were unlinked w/o being closed first.
Now encode everything in UTF-8 instead of Latin9 since that's what
is gonna be used afterwards.
Fixed buffer overflow