refactor insert gallery