fix NPE and mime type discovery