gallery logic