Implementation is duplicated, but tolerate this for now, because there's no clear idea how to de-dup it.