some refactoring, added beginnings of removing unused media, made media type first and uncompressed file in epub and other bug fixes