refactored gallery opening