Continue work on #4812

Supersedes #5013