improve script for gallery creation