Refactor gallery template