First refactor for #1572