added prepareGallery( ) function