Fixed 'fclose() expects..., null given' error
Fixed wrongly closed file resources