commit before error refactor