Partly revert 13945ed73147 and add testcase.