Refactor for upstream