Cleanup of texture-loading code, with diagnostics added