thorough commenting and refactored mimetype handler