Refactor from #2190

See #2190 and then this.