Made count and closing files better