gallery: refactoring