Optimize modal gallery plugin