Main gallery code