minor refactoring in gallery