factor out stage and commit