update with Josh's code to fix galleries.