Add media type control and fix bugs.