Gallery code cleanup