Backport from refactor branch