A replacement for #2566

see #2566