Fixed file opening in binary mode, closed connection and file after done.