Fixed a bug where a file resource was not closed.
Also some improved error handling, and fixed some warnings.