This reapplies ca134c39, effectively reverting commit d2f206e0. Minor test changes to make the test pass.