Factored out extra stat() call.

Changed mdt_res_init into function. Slight optimization to MIME type
detector. Minor refactorings & corrections.