merge gallery code