refactor the gallery