refactor of gallery to reduce html size