Refactor following upstream merge