Refactor gallery module