optimize media gallery functionality and styles